package com.reform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.reform.pojo.project.ProjectClassification;
import com.reform.mapper.ProjectClassificationMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.IProjectClassificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 项目分类表（专家） 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-07-15
 */
@Service
public class ProjectClassificationServiceImpl extends ServiceImpl<ProjectClassificationMapper, ProjectClassification> implements IProjectClassificationService {

    @Autowired
    ProjectClassificationMapper projectClassificationMapper;

    @Override
    public Integer creatProjectClassification(ProjectClassification projectClassification) {
        return projectClassificationMapper.insert(projectClassification);
    }

    @Override
    public Integer updateProjectClassification(ProjectClassification projectClassification) {
        return projectClassificationMapper.updateById(projectClassification);
    }

    @Override
    public Integer deleteProjectClassification(String batch_id) throws SQLException {
        Map<String, Object> map = new HashMap<>();
        map.put("batch_id", batch_id);
        return projectClassificationMapper.deleteByMap(map);
    }

    @Override
    public Result getClassificationById(String batchId) throws SQLException {
        try {
            return Result.success(ResultCode.SUCCESS, projectClassificationMapper.selectOne(new QueryWrapper<ProjectClassification>().eq("batch_id", batchId)));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(ResultCode.FAILURE);
        }
    }
}
